<html>
<head><meta charset="utf-8"><title>HygienicIdent abstraction · t-compiler/wg-incr-comp · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/index.html">t-compiler/wg-incr-comp</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/HygienicIdent.20abstraction.html">HygienicIdent abstraction</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="221972277"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/241847-t-compiler/wg-incr-comp/topic/HygienicIdent%20abstraction/near/221972277" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/HygienicIdent.20abstraction.html#221972277">(Jan 07 2021 at 17:25)</a>:</h4>
<p><span class="user-mention" data-user-id="123856">@Vadim Petrochenkov</span>, related to your PR <a href="https://github.com/rust-lang/rust/issues/80765">#80765</a>:<br>
I have a branch embryo (a bud?) introducing an <code>HygienicIdent</code> abstraction, for just <code>Symbol + SyntaxContext</code>.<br>
The objective was originally to make progress on span-less HIR.<br>
Are you interested? Do you have use cases with more immediate applications?</p>



<a name="222129473"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/241847-t-compiler/wg-incr-comp/topic/HygienicIdent%20abstraction/near/222129473" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/HygienicIdent.20abstraction.html#222129473">(Jan 08 2021 at 21:38)</a>:</h4>
<p>I've seen this message but didn't have a chance to answer in detail yet.<br>
<code>SyntaxContext</code> still contains more data than necessary on a "good path" (e.g. info about expansions of transparent and semi-transparent macros), we should be able to do better.</p>



<a name="222130346"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/241847-t-compiler/wg-incr-comp/topic/HygienicIdent%20abstraction/near/222130346" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/HygienicIdent.20abstraction.html#222130346">(Jan 08 2021 at 21:45)</a>:</h4>
<p>What's the minimal amount of information that is required for this?</p>



<a name="222761592"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/241847-t-compiler/wg-incr-comp/topic/HygienicIdent%20abstraction/near/222761592" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/HygienicIdent.20abstraction.html#222761592">(Jan 14 2021 at 18:34)</a>:</h4>
<p>Let me clarify the basics. So the general idea is that:</p>
<ul>
<li>Only a subset of <code>Span</code> data is used during successful compilation ("good path"), let's call it <code>SpanLite</code> this subset changes more rarely during successive compilations, so incremental compilation benefits from hashing it to determine that something changed instead of hashing the whole span.</li>
<li>Full <code>Span</code> is used only on erroneous paths, or by rarely invoked "leaf" queries, so it can be kept in some side table with slow access to it.</li>
</ul>



<a name="222762184"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/241847-t-compiler/wg-incr-comp/topic/HygienicIdent%20abstraction/near/222762184" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/HygienicIdent.20abstraction.html#222762184">(Jan 14 2021 at 18:38)</a>:</h4>
<p>I think the most important thing here is to confirm that full <code>Span</code> is indeed not used on good path, because if it is used then the whole scheme breaks and we are simply slowing things down and make them more complex without any benefit.<br>
This property is highly non-obvious, for example in <a href="https://github.com/rust-lang/rust/issues/73996">#73996</a> we naively assumed that types are not pretty-printed on good path (with path shortening such pretty-printing calls a very heavy query), but that turned out to not be true at all.</p>



<a name="222762547"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/241847-t-compiler/wg-incr-comp/topic/HygienicIdent%20abstraction/near/222762547" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/HygienicIdent.20abstraction.html#222762547">(Jan 14 2021 at 18:40)</a>:</h4>
<p>For spans one obvious case is debuginfo - it it's generated, then full spans are used. How do you plan to deal with this case?</p>



<a name="222763452"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/241847-t-compiler/wg-incr-comp/topic/HygienicIdent%20abstraction/near/222763452" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/HygienicIdent.20abstraction.html#222763452">(Jan 14 2021 at 18:46)</a>:</h4>
<p>Regarding the minimal amount of information, it's <code>SyntaxContext</code> with <code>normalize_to_macros_2_0</code> applied, that's what is needed for resolving names of associated items (which is always done on "good path").<br>
After lowering to HIR unnormalized <code>SyntaxContext</code> should only be used for 1) "are we in external macro?" checks in lints and 2) edition checks (if I'm not forgetting anything).</p>
<p>The lint checks can probably be performed last, only in cases when we are sure that we are going to report the lint otherwise.<br>
The post-AST-lowering edition checks need some audit and review, I'm not sure how often they are done and on what paths.</p>
<p>Anyway, full unnormalized <code>SyntaxContext</code> should be a good first approximation to the <code>HygienicIdent</code> (which I would probably call just <code>hir::Ident</code>).</p>



<a name="222763622"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/241847-t-compiler/wg-incr-comp/topic/HygienicIdent%20abstraction/near/222763622" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/HygienicIdent.20abstraction.html#222763622">(Jan 14 2021 at 18:47)</a>:</h4>
<p>One more thing - IIRC, some HIR nodes only use <code>Ident</code>s due to span locations, not hygiene, they can be turned into simple <code>Symbol</code>s without <code>SyntaxContext</code>s if span locations are outlined.</p>



<a name="222765233"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/241847-t-compiler/wg-incr-comp/topic/HygienicIdent%20abstraction/near/222765233" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/HygienicIdent.20abstraction.html#222765233">(Jan 14 2021 at 18:58)</a>:</h4>
<p><span class="user-mention silent" data-user-id="123856">Vadim Petrochenkov</span> <a href="#narrow/stream/241847-t-compiler.2Fwg-incr-comp/topic/HygienicIdent.20abstraction/near/222762547">said</a>:</p>
<blockquote>
<p>For spans one obvious case is debuginfo - it it's generated, then full spans are used. How do you plan to deal with this case?</p>
</blockquote>
<p>worth calling out panic! and every unwrap()/expect() (track_caller method), too, in terms of location information - which is not controllable by user</p>



<a name="225418154"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/241847-t-compiler/wg-incr-comp/topic/HygienicIdent%20abstraction/near/225418154" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/HygienicIdent.20abstraction.html#225418154">(Feb 06 2021 at 16:00)</a>:</h4>
<p>Thanks for this detailed explanation.<br>
I don't have a satisfactory design for storing the full span for each Ident.<br>
1/ The simplest solution would be to add some "hir::IdentId" (as a newtype for HirId or a more compact representation) and store everything out of the tree (= a side table). This would lead to a lot of churn in downstream crates.<br>
2/ Another solution would be to try some hybrid between storing the HygienicIdent in-tree and its span out. This would require some <code>ident_span: HirId -&gt; Span</code> map. Unfortunately, some HIR nodes have Idents and no HirId.<br>
I tend to favour solution 2, since there is already an <code>ident_span</code> metadata output. Since it will be sparse, I imagine using the same kind of method as for attributes.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>